package com.jiuqi.bi.database.mysql.metadata;

import com.jiuqi.bi.database.metadata.*;
import com.jiuqi.bi.sql.DataTypes;
import com.jiuqi.bi.util.OrderGenerator;
import com.jiuqi.bi.util.StringUtils;

import java.sql.*;
import java.util.*;

public class MySQLMetadata extends DefaultSQLMetadata {
	// 查询当前数据库时间
	private static final String SQL_QUERY_CURRENT_TIME = "select current_timestamp(3)";
	public MySQLMetadata(Connection conn) {
		super(conn);
	}

	@Override
	public long getDatabaseTimestamp() throws SQLException{
		PreparedStatement ps = conn.prepareStatement(SQL_QUERY_CURRENT_TIME);
		try {
			ResultSet rs = ps.executeQuery();
			try {
				long time = 0;
				if (rs.next()) {
					Timestamp timestamp = rs.getTimestamp(1);
					time = timestamp.getTime();
				}
				return time;
			} finally {
				rs.close();
			}
		} finally {
			ps.close();
		}
	}


}
